package countBeautifulPairs;

public class Solution {
    public int countBeautifulPairs(int[] nums) {
        int ans = 0;
        for (int i = 0; i < nums.length; i++) {
            for (int j = i+1; j < nums.length; j++) {
                // 第一个数字和最后一个数字
                int a = Integer.toString(nums[i]).charAt(0) - '0';
                String s = Integer.toString(nums[j]);
                int b = s.charAt(s.length()-1)-'0';
                if(gcd(a,b) == 1) {
                    ans++;
                }
            }
        }
        return ans;
    }
    private int gcd(int a,int b) {
        if(a == 0) {
            return b;
        }
        return gcd(b,a%b);
    }
}
